/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.sys.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.Api;

import com.moon.admin.sys.entity.SysTenantEntity;
import com.moon.admin.sys.domain.SysTenantQuery;
import com.moon.admin.sys.service.SysTenantService;
import com.moon.admin.framework.util.ToolUtils;
import com.moon.admin.framework.secure.annotation.FormRepeat;
import com.moon.admin.framework.secure.annotation.PreAuth;
import com.moon.admin.framework.springmvc.domain.R;
import com.moon.admin.framework.syslog.annotation.SysLog;
import com.moon.admin.framework.domain.MoonPage;
import com.moon.admin.framework.mybatisplus.query.Condition;

/**
 * 租户管理 操作处理
 * 
 * @author moon
 */
@RestController
@RequestMapping("/sys/sysTenant")
@Api(value="租户管理",tags="租户管理服务")
public class SysTenantController{
	
    @Autowired
    private SysTenantService sysTenantService;

    @ApiOperation(value="租户管理列表")
    @PostMapping(value = "list")
    @PreAuth("sys_sysTenant_view")
    public R<MoonPage<SysTenantEntity>> list(@RequestBody SysTenantQuery sysTenant) {
        IPage<SysTenantEntity> pages = sysTenantService.page(Condition.getPage(sysTenant),Condition.getQueryWrapper(new SysTenantEntity(),sysTenant));
    	return R.success(MoonPage.of(pages));
    }

    @ApiOperation(value="租户管理添加/编辑")
    @PostMapping(value = "editSave")
    @PreAuth(value={"sys_sysTenant_add","sys_sysTenant_edit"})
    @SysLog(mod="租户管理服务",fun="保存")
    @FormRepeat
    public R<String> editSave(@RequestBody SysTenantEntity sysTenant){
        sysTenantService.saveOrUpdate(sysTenant);
        return R.success();
    }

    @GetMapping("/removeByIds")
    @ApiOperation(value = "租户管理", notes = "传入ids")
    @PreAuth("sys_sysTenant_remove")
    @SysLog(mod="租户管理服务",fun="删除")
    @FormRepeat
    public R<Boolean> removeByIds(@ApiParam(value = "主键集合", required = true)String ids) {
        return R.status(sysTenantService.removeByIds(ToolUtils.toIntList(ids)));
    }
}